package controller;

import entity.Emp;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/validate")
public class ValidateController {

    @RequestMapping("/show")
    public String show(Emp emp){
        System.out.println("ValidateController.show()");
        return "validate";
    }

    @RequestMapping("/submit")
    public String submit(@Valid Emp emp, Errors errors){
        System.out.println("ValidateController.submit()");

        if(errors.hasErrors()){
            return "validate";
        }

        System.out.println("emp = " + emp);

        return "redirect:/validate/show";
    }

}
